package com.donger.common.swagger.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author 7326
 */
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

    @Bean
    public Docket upmsApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.donger.business.upms"))
                .paths(PathSelectors.any())
                .build()
                .groupName("upms");
    }
    @Bean
    public Docket storageApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.donger.business.storage"))
                .paths(PathSelectors.any())
                .build()
                .groupName("storage");
    }

    @Bean
    public Docket messageApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.donger.business.message"))
                .paths(PathSelectors.any())
                .build()
                .groupName("message");
    }

    @Bean
    public Docket appApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.donger.business.app"))
                .paths(PathSelectors.any())
                .build()
                .groupName("app");
    }

    @Bean
    public Docket cmsApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.donger.business.cms"))
                .paths(PathSelectors.any())
                .build()
                .groupName("cms");
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Base-boot 接口文档")
                .description("Base-boot 接口文档")
                .termsOfServiceUrl("http://localhost:8999/")
                .contact(new Contact("base-boot", "", "developer@mail.com"))
                .version("3.0.0.alpine")
                .build();
    }

}
